package adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.itboye.hutoubenjg.R;

import java.util.List;

import bean.MyAddressBean;


/***
 * 我的收货地址
 * @author mr.w
 */
public class AddressListAdapter extends android.widget.BaseAdapter {

    List<MyAddressBean> datas;
    int position;
    int layoutId;
    Activity context;

    public AddressListAdapter(Activity context, List<MyAddressBean> datas) {
        this.context = context;
        this.datas = datas;
    }


    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.include_address,null);
            holder.address_people= (TextView) convertView.findViewById(R.id.address_people);
            holder.address_phone= (TextView) convertView.findViewById(R.id.address_phone);
            holder.address_detail= (TextView) convertView.findViewById(R.id.address_detail);
            holder.is_moren= (TextView) convertView.findViewById(R.id.is_moren);
            convertView.setTag(holder);

        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.address_people.setText(datas.get(position).getContactname());
        holder.address_phone.setText(datas.get(position).getMobile());
        holder.address_detail.setText(datas.get(position).getProvince()+datas.get(position).getCity()+datas.get(position).getArea()+datas.get(position).getDetailinfo());

        if(datas.get(position).getIs_default()==1){
            holder.is_moren.setVisibility(View.VISIBLE);
        }else{
            holder.is_moren.setVisibility(View.GONE);
        }

        return convertView;
    }

    public  class ViewHolder {
        TextView address_people,address_phone,address_detail;//姓名，电话,详细地址
        TextView is_moren;//默认
    }
}
